<?php
/**
 *
 * @author    Lucian Daia < lucian.daia@live.com >
 * @copyright 2010, Lucian Daia
 * @package   KChunk
 */
class KChunk_Worker
{
	/**
	 * The stream used to communicate with the child process
	 * @var resource
	 */
	protected $_connStream = null;

	/**
	 * Attempts to open a read-only pipe to the child process
	 */
	public function openConnection()
	{
		$this->_connStream = popen($this->_buildCommand(), 'r');
	}

	/**
	 * Reads up to $bufferSize bytes from the stream
	 *
	 * @todo Check if the data stream exists, other error checking.
	 *
	 * @param int $bufferSize
	 */
	public function readData($bufferSize)
	{
		return fread($this->_connStream, $bufferSize);
	}
}